import http from '../../request/index.js'
import store from '@/store/index.js'

/**
 * 登录
 */
export function login(data) {
	return http.BaseRequest({
		url: '/engineer/login',
		method: 'post',
		data: data,

	})
}

/**
 * 获取用户信息
 */
export function getInfo(id) {
	console.log("api接口中的" + id)
	return http.TokenRequest({
		url: '/engineer/' + id,
		method: 'get',
	})
}

/**
 * 登出
 */
export function logout(token) {
	return http.TokenRequest({
		url: '/engineer/logout',
		method: 'post',
		params: {
			token: token
		}
	})
}


//############################消息#####################################
/**
 * 根据工程师id获取维修消息记录列表
 */
export function getRepairByEngineerIdList(id, limit, page) {
	return http.TokenRequest({
		url: `/repair?action=byEngineer&engineer_id=${id}&limit=${limit}&page=${page}`,
		method: 'get',

	})
}
/**
 * 根据工程师id获取维修消息记录列表
 */
export function getRepairList(limit, page) {
	return http.TokenRequest({
		url: `/repair?action=&limit=${limit}&page=${page}`,
		method: 'get',

	})
}



/**
 * 根据维修单id查询维修消息详情
 */
export function getRepairDetailsByEquipmentId(id) {
	return http.TokenRequest({
		url: "/repair/" + id,
		method: 'get',
	})
}



/**
 * @param {Object} date
 * 任务转让
 */
// /repair/16?action=UpdateRepairEngineer&engineer_id=1
export function transferRepair(info) {
	return http.TokenRequest({
		url: "/repair/" + info.id + "?action=UpdateRepairEngineer&engineer_id=" + info.engineer_id,
		method: 'put',
	})
}



/**
 * @param {Object} date
 * 查询工程师列表
 */
export function getEngineerList() {
	return http.TokenRequest({
		url: `/engineer?limit=10000000&page=1`,
		method: 'get',
	})
}


//############################设备#####################################


/**
 * 创建设备
 *  equipmentTypeNumber: '',//设备型号
 *	configuration: '',//设备配置
 *	fuselageNumber: '',//设备机身号
 *	inkTankTypeNumber: '',//墨水溶剂型号
 *	installDate: '',//安装日期
 *	maintainPeople: '',//负责人姓名
 *	subordinateCompany: '',//客户公司
 *	customerDetailedAddress: '',//客户公司地址
 *	customer: '',//客户联系人
 *	customerContact: '',//客户联系方式
 *	imgUrl: this.basicArr //图片地址
 * 
 */
// /equipment/create?type=日立 小字符喷码机 2120&configure=常规配置 自动Ai&number=12345678&ink_type=日立 201-0001-085 抗迁移白色溶剂&installDate=2020-05-04&engineer=耀龙啊&user_dep=某某某公司&user_address=**市**县**村&user=张三&user_phone=12345678910
export function creteEquipment(info) {
	return http.TokenRequest({
		url: "/equipment/" + info.equipment_id + "?action=create&type=" + info.equipmentTypeNumber +
			"&configure=" + info.configuration +
			"&number=" + info.fuselageNumber +
			"&ink_type=" + info.inkTankTypeNumber +
			"&solvent_type=" + info.solventType +
			"&installDate=" + info.installDate +
			"&engineer_id=" + info.maintainPeopleId +
			"&user_dep=" + info.subordinateCompany +
			"&user_address=" + info.customerDetailedAddress +
			"&user=" + info.customer +
			"&user_phone=" + info.customerContact +
			"&file=" + info.imgUrl[0],
		method: 'put',

	})
}

/**
 * 查看当前工程师的设备列表
 */
export function getEquipmentListByengineer(id, limit, page) {
	return http.TokenRequest({
		url: `/equipment?action=byEngineer&engineer_id=${id}&limit=${limit}&page=${page}`,
		method: 'get',

	})
}
/**
 * 根据设备id查找设备的工单历史记录
 */
export function getWorkOderListByEquipmentId(id, limit, page) {
	return http.TokenRequest({
		url: `/report?equipment_id=${id}&limit=${limit}&page=${page}&sortField=createTime&sort=DESC`,
		method: 'get'

	})
}


/**
 * 根据设备id获取设备信息
 */

export function getEquipmentById(id) {
	return http.TokenRequest({
		url: '/equipment/' + id + "?engineer_id=",
		method: 'get'

	})

}

/**
 * 根据设备id获取设备信息
 */

export function getEquipmentByIdAndByEngineerId(id, engineer_id) {
	return http.TokenRequest({
		url: '/equipment/' + id + "?engineer_id=" + engineer_id,
		method: 'get'

	})

}

/**
 * 获取所有设备型号
 */

export function getEquipmentTypeList() {
	return http.TokenRequest({
		url: `/type`,
		method: 'get'
	})
}

//############################工单#####################################




/**
 * 创建工作报告
 * 
 * 
 * equipment_id:'',//设备id
 * reportType: "",//工单类型
 * fault: "",//故障描述
 * isSolve: '',//是否解决
 * solution:"", //解决方案
 * isChangeParts:'',//是否更换配件
 * parts:"",//配件
 * imgurl:[]//图片地址
 *  * 
 * 
 */
export function createReport(info) {
	return http.TokenRequest({
		url: "/report?action=create&type=" + info.type +
			"&reason=" + info.reason +
			"&solution=" + info.solution +
			"&result=" + info.result +
			"&fitting=" + info.fitting +
			"&fitting_addtion=" + info.fitting_addtion +
			"&equipment_id=" + info.equipment_id +
			"&repair_id=" + info.repair_id +
			"&file[]=" + info.file[0] +
			"&file[]=" + info.file[1] +
			"&file[]=" + info.file[2] +
			"&file[]=" + info.file[3] +
			"&file[]=" + info.file[4] +
			'&engineer_id=' + store.getters.id,
		method: 'post',

	})
}


/**
 * 
 * 根据工程师id获取工单列表
 */
export function getReportListByEngineerId(id, type, limit, page) {
	return http.TokenRequest({
		url: `/report?engineer_id=${id}&type=${type===-1?'':type}&equipment_id=&limit=${limit}&page=${page}&sortField=createTime&sort=desc`,
		method: 'get',
	})
}

/**
 * 
 * 获取所有工单列表
 */
export function getReportAllList(type, limit, page) {
	return http.TokenRequest({
		url: `/report?type=${type===-1?'':type}&equipment_id=&limit=${limit}&page=${page}&sortField=id&sort=desc`,
		method: 'get',
	})
}

/**
 * 查看工单详细信息
 */
export function getReportDetailsByEquipmentId(id) {
	
	return http.TokenRequest({
		url: "/report/" + id,
		method: 'get'
	})
}

/**
 * 更新工单
 */
export function updateReport(info) {
	let fileParams = ''
	if (info.file.length > 0) {
		info.file.forEach(item => {
			fileParams += "&file[]=" + item
		})
	} else {
		fileParams = '&file[]='
	}
	console.log(fileParams)
	return http.TokenRequest({
		url: "/report/" + info.id + "?type=" + info.type +
			"&reason=" + info.reason +
			"&solution=" + info.solution +
			"&result=" + info.result +
			"&fitting=" + info.fitting +
			fileParams +
			"&fitting_addtion=" + info.fitting_addtion,
		method: 'put',
	})
}


/**
 * 替换二维码
 */
export function replaceQrCode(equipmentId, equipmentNumber) {
	return http.TokenRequest({
		url: `/equipment/${equipmentId}?action=update&number=${equipmentNumber}`,
		method: 'put',
	})
}